<?php
	session_name('YourVisitID');
	session_start ();
	$error = array ();
	
	if (isset ( $_SESSION ['name'] )) {
		require_once '../mysql_connection/for_m_sheets.php';
	} else {
		$error [] = 'You have not login!';
	}
	if(isset($_POST['getsheet_name'])){
		$sheets = findSheetByUser($_POST['username']);
	}else if(isset($_POST['getsheet_type'])){
		$sheets = findSheetByUser($_POST['goods_type_search']);
	}
?>

<?php 
include ('../include_htmls/manage_head.html');
?>

<?php
if (empty ( $error )) {
?>
	<form action="manage_sheets.php" method="post">
		<div align="center">
			UserName:
			    <input type="text" name="username" size="15" maxlength="20" />
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			
		    <input type="submit" value="Search"/>
		    <input type="hidden" name="getsheet_name" value="TRUE" />
		</div>
	</form>
	<form action="manage_sheets.php" method="post">
		<div align="center">
			SheetType:
			    <select name="goods_type_search" size=1>
			        <option value="1">NOT CHARGED</option>
			    	<option value="2">GET GOODS</option>
			    	<option value="3">NOT GET GOODS</option>
			    </select>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			&nbsp;&nbsp;
			
		    <input type="submit" value="Search"/>
		    <input type="hidden" name="getsheet_type" value="TRUE" />
		</div>
	</form>
<?php 
	if (!empty($sheets)){
?>
		<table cellspacing="0" cellpadding="3" border="1" align="left" width="800" height="100">
    			    				    <tr>
    			    					    <th align="center">UserName</th>
    			    					    <th align="center">State</th>
    			    					    <th align="center">Time</th>
    			    					    <th align="center">Receiver</th>
    			    					    <th align="center">Address</th>
    			    					    <th align="center">Zip</th>
    			    					    <th align="center">Phone</th>
    			    					    <th align="center">DeliverType</th>
    			    					    <th align="center">DeliverTime</th>
    			    					    <th align="center">PaymentType</th>
    			    					    <th align="center">ChangeState</th>
    			    					</tr>
<?php 
		foreach ($sheets as $onesheet){	
?>
			<tr>
    			    					    <th align="center"><?php echo $onesheet[1];?></th>
    			    					    <th align="center"><?php echo $onesheet[2];?></th>
    			    					    <th align="center"><?php echo $onesheet[3];?></th>
    			    					    <th align="center"><?php echo $onesheet[4];?></th>
    			    					    <th align="center"><?php echo $onesheet[5];?></th>
    			    					    <th align="center"><?php echo $onesheet[6];?></th>
    			    					    <th align="center"><?php echo $onesheet[7];?></th>
    			    					    <th align="center"><?php echo $onesheet[8];?></th>
    			    					    <th align="center"><?php echo $onesheet[9];?></th>
    			    					    <th align="center"><?php echo $onesheet[10];?></th>
    			    					    <th align="center">
    			    					    	<form action="manage_sheets.php" method="post">
    			    								<input type="submit" value="delete sheet">
    			    								<input type="hidden" value=<?php echo "\"".$onesheet[0]."\""?>" name="delete_sheet">
    			    							</form>
    			    					    </th>
    			    					</tr>
<?php 
		}
?>
		</table>
<?php 
	}
?>
<?php
} else {
	echo '<h1 align="center" id="mainhead">Error!</h1>
	<p align="center" class="error">The following error(s) occurred:<br />';
	foreach ( $error as $msg ) {
		echo " - $msg<br />\n";
	}
	echo '</p><p align="center" >Please login first.</p>';
	echo '<p align="center" ><a href="login.php"><img src="../images/manager_login.jpg" width="100" hight="25" border="0"/></a></p>';
}
?>

<?php
include ('../include_htmls/manage_foot.html');
?>
